import { $get } from '@js/authRequest'
import { strToNum } from '@src/assets/js/tool'

// 获取超审限案件数量
export async function requestOne () {
  const res = await $get('/api/xapc/casestat/limitStat', {
    conly: 1,
    type: 'trial_limit',
    degree: 'over',
    statusex: '在办'
  })
  if (res.status !== 1) {
    throw new Error(res.message)
  }
  return res.data
}

// 获取延期组庭案件数量
export async function requestTwo () {
  const res = await $get('/api/xapc/casestat/limitStat', {
    conly: 1,
    type: 'arbitrator_sel_limit',
    degree: 'over',
    statusex: '在办'
  })
  if (res.status !== 1) {
    throw new Error(res.message)
  }
  return res.data
}

// 查询统计案件 中止、延长审限次数
export async function requestThree () {
  const res = await $get('/api/xapc/casestat/limitExtendedStat', {
    conly: 1
  })
  if (res.status !== 1) {
    throw new Error(res.message)
  }
  return formatData(res.data)
}

// 格式化数据
function formatData (list) {
  const m = {}
  list.forEach(li => {
    m[li.count_level] = li.exnum
  })
  m[0] = list.reduce((a, b) => ({ exnum: strToNum(a.exnum) + strToNum(b.exnum) })).exnum
  return m
}

// 中止
export async function requestFour () {
  const res = await $get('/api/xapc/casestat/suspensionStat', {
    conly: 1
  })
  if (res.status !== 1) {
    throw new Error(res.message)
  }
  return res.data
}
